package com.big.merchan.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.big.common.result.Result;
import com.big.merchan.service.MerchandiseInfoService;
import com.big.merchan.service.MerchandiseService;
import com.big.model.model.merchandise.MerchandiseDetail;
import com.big.model.model.merchandise.MerchandiseInfo;
import com.big.model.vo.merchandise.MerchanParams;
import com.big.model.vo.merchandise.MerchanQueryVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * 商品控制器
 */
@RestController
@RequestMapping("/api/merchan/merchandise")
public class MerchanInfoDiseController {


       @Autowired
       private MerchandiseService merchandiseService;


       @Autowired
       private MerchandiseInfoService merchandisesService;

       //商品描述列表
       @ApiOperation(value = "商品列表")
       @PostMapping("auth/{page}/{limit}")
       public Result merchanlist(
                          @PathVariable Long page,
                          @PathVariable Long limit,
                          MerchanParams merchanParams) {
           Page<MerchandiseDetail> pageParam = new Page<>(page,limit);
           IPage<MerchandiseDetail> pageModel = merchandiseService.MerchanInfos(pageParam,merchanParams);
           System.out.println(merchanParams);
           return Result.ok(pageModel);
       }

    //商品列表(条件查询分页)
        @ApiOperation(value = "商品详情")
        @PostMapping("auth/info/{productID}")
        public Result merchaninfo(@PathVariable("productID") Long productID) throws ParseException {
            MerchandiseInfo Model = merchandisesService.findInfoMerchandise(productID);
           return Result.ok(Model);
      }


      //商品描述详情
      @ApiOperation(value = "商品描述详情")
      @GetMapping("auth/FindInfo/{did}")
      public MerchandiseDetail findMerchanInfo(@PathVariable("did") String did){
          MerchandiseDetail Model = merchandiseService.FindMerchanInfo(did);
          return Model;
      }

    //商品详情
    @ApiOperation(value = "商品详情")
    @GetMapping("auth/findMerchanInfo/{id}")
    public MerchandiseInfo findInfoMerchandise(@PathVariable("id") String id) throws ParseException {
        MerchandiseInfo Model =merchandisesService.findInfoMerchandise(Long.valueOf(id));
        return Model;
    }


}
